import web, datetime
from config import settings


db = settings.db

def get_users():
    return db.select('id', order='id')

def get_post(id):
    try:
        return db.select('article', where='id=$id', vars=locals())[0]
    except IndexError:
        return None
    
def get_posts():
    return db.select('article', order='id')
    
def post_new(title, content):
    db.insert('article', title=title, content=content, post_time=datetime.datetime.now())
        
    
def post_update(id, title, content):
    db.update('article', where="id=$id", vars=locals(), title=title, content=content)

def post_delete(id):
    db.delete('article', where="id=$id", vars=locals())